package thread.start;

import org.junit.Test;

import java.util.concurrent.TimeUnit;

/**
 * @author cyt
 * @create 2020-09-24 11:35
 */
public class StatusTest {

    @Test
    public void testStatus() {
        Thread aa = new Thread(() -> {
            test();
        }, "AA");

        Thread bb = new Thread(() -> {
            test();
        }, "BB");


        aa.start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        bb.start();

        System.out.println(aa.getName() + " - > " + aa.getState());
        System.out.println(bb.getName() + " - > " + bb.getState());
    }

    private synchronized void test() {
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
